package com.yyn.seckill.util;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

@Component
public class MD5Util {
public static String md5(String src){
    return DigestUtils.md5Hex(src);
}
//盐值 要前后端统一
private static final String SALT="1a2b3c4d";

//第一次加密
public static String oneMd5(String inputPass){
    String str = SALT.charAt(0)+SALT.charAt(2)+inputPass+SALT.charAt(5)+SALT.charAt(4);
    return md5(str);
}
    //第二次加密
    public static String twoMd5(String inputPass,String Salt){
        String str = Salt.charAt(0)+Salt.charAt(2)+inputPass+Salt.charAt(5)+Salt.charAt(4);
        return md5(str);
    }
    //加密放入数据库
    public static String inputPassToDBPass(String inputPass,String salt){
        String one = oneMd5(inputPass);
        String twoMd5 = twoMd5(one, SALT);
        return twoMd5;
    }

    public static void main(String[] args) {
    String a="123456";
        String s = oneMd5(a);
        String s1 = twoMd5(s,SALT);
        String s2 = inputPassToDBPass(a, SALT);
        System.out.println("one:"+s);
        System.out.println("two:"+s1);
        System.out.println("db:"+s2);
    }}
